/****************************************************************/
/*																*/
/*  AddUserDlg.cpp												*/
/*																*/
/*  Implementation of the CAddUserDlg class.					*/
/*	This class is a part of the FTP Server Application			*/
/*																*/
/*  Programmed by Pablo van der Meer							*/
/*  Copyright Pablo Software Solutions 2002						*/
/*	http://www.pablovandermeer.nl								*/
/*																*/
/*  Last updated: 10 july 2002									*/
/*																*/
/****************************************************************/


#include "stdafx.h"
#include "eDASexpressApp.h"
#include "AddUserDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif



CAddUserDlg::CAddUserDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAddUserDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAddUserDlg)
	m_strName = _T("");
	//}}AFX_DATA_INIT
}


void CAddUserDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAddUserDlg)
	DDX_Control(pDX, IDCANCEL, m_cbtnCancel);
	DDX_Control(pDX, IDOK, m_cbtnOK);
	DDX_Control(pDX, IDC_EDT_LIMITEDTIMES, m_cedtLimitedTimes);
	DDX_Control(pDX, IDC_DATE_DEADLINE, m_cdtimeDeadline);
	DDX_Control(pDX, IDC_CHK_DEADLINE, m_cchkIfDeadline);
	DDX_Control(pDX, IDC_CHK_LIMITEDTIMES, m_cchkIfLimitTimes);
	DDX_Control(pDX, IDC_CHK_LIMIT, m_cchkIfLimited);
	DDX_Control(pDX, IDC_STC_OPERATOR, m_cstcOperator);
	DDX_Control(pDX, IDC_STC_LIMITATION, m_cstcLimitation);
	DDX_Control(pDX, IDC_SPN_LIMITEDTIMES, m_cspnLimitedTimes);
	DDX_Text(pDX, IDC_NAME, m_strName);
	DDV_MaxChars(pDX, m_strName, 60);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAddUserDlg, CDialog)
	//{{AFX_MSG_MAP(CAddUserDlg)
	ON_BN_CLICKED(IDC_CHK_LIMIT, OnChkLimit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BOOL CAddUserDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	if (!m_strTitle.IsEmpty())
		SetWindowText(m_strTitle);

	CenterWindow();
	return TRUE;
}



void CAddUserDlg::OnChkLimit() 
{
	switch (m_cchkIfLimited.GetCheck())
	{
	default:
		// FALL THROUGH
	case BST_UNCHECKED:
		ShowLimitationOptions( FALSE );
		break;
	case BST_CHECKED:
		ShowLimitationOptions();
		break;
	}
}

void CAddUserDlg::ShowLimitationOptions(BOOL ifShow)
{
	if (m_cstcLimitation.IsWindowVisible())
		return;

	int iShow= (TRUE == ifShow) ? SW_SHOW : SW_HIDE;
	m_cstcLimitation.ShowWindow( ifShow );
	m_cchkIfDeadline.ShowWindow( ifShow );
	m_cdtimeDeadline.ShowWindow( ifShow );
	m_cchkIfLimited.ShowWindow( ifShow );
	m_cedtLimitedTimes.ShowWindow( ifShow );
	m_cspnLimitedTimes.ShowWindow( ifShow );

	static const int iLimitationOptionsHeight= GetLimitationOptionsHeight();
	static const UINT nMoveFlag= SWP_NOACTIVATE| SWP_NOOWNERZORDER| SWP_NOZORDER| SWP_NOSIZE;
	int iHeightMoved= (TRUE == ifShow) ? iLimitationOptionsHeight : (-iLimitationOptionsHeight);
	CRect rcStcOperator;
		m_cstcOperator.GetWindowRect( rcStcOperator );
	VERIFY( m_cstcOperator.SetWindowPos( NULL, rcStcOperator.left, rcStcOperator.top+iHeightMoved, 0, 0, nMoveFlag ) );
	CRect rcBtnOK;
		m_cbtnOK.GetWindowRect( rcBtnOK );
	VERIFY( m_cbtnOK.SetWindowPos( NULL, rcBtnOK.left, rcBtnOK.top+iHeightMoved, 0, 0, nMoveFlag ) );
	CRect rcBtnCancel;
		m_cbtnCancel.SetWindowPos( NULL, rcBtnCancel.left, rcBtnCancel.top+iHeightMoved, 0, 0, nMoveFlag );
}

int CAddUserDlg::GetLimitationOptionsHeight()
{
	ASSERT( NULL != m_cstcLimitation.GetSafeHwnd() );
		CRect rcStcLimitation;
			m_cstcLimitation.GetWindowRect( rcStcLimitation );
		CRect rcStcOperator;
			m_cstcOperator.GetWindowRect( rcStcOperator );
	int iYSpan = rcStcOperator.top - rcStcLimitation.top;
	ASSERT(0 != iYSpan);
	return( iYSpan );
}
